// delay for given number of microseconds (use 22-65535) or milliseconds (1-65535) using timer 3
// delayT3_us minimum is 22 us
// (C) Copyright 2009, 2010 Communications Programming, Inc.

#include "userLib.h"
#include "timers.h"

void delayT3_init()					// init timer for first use
{
	T3CON = T3CON_VAL;				// timer on, set prescale 
}

void delayT3_us( uint16 us )		// delay a given number of microseconds
{
	WriteTimer3(0);
	us *= timer_ticks_per_microsec;
	if( us >= DELAY_OVERHEAD_TICKS )
	{
		us -= DELAY_OVERHEAD_TICKS;
		while( ReadTimer3() < us )
		{}
	}	
}

void delayT3_ms( uint16 ms )		// delay a given number of milliseconds (1-65535)
{
	while( ms-- )
	{
		delayT3_us(1000);	
	}
}

